/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;

import GUI.TableSelectionDemo.MyTableModel;


/**
 *
 * @author paja0902
 *
 */
public class GUI extends JFrame implements ActionListener
{
    private     JMenuBar menuBar;
    private     JMenuItem exit;
    private     JMenuItem writeOut;
    private     JMenuItem save;
    private     JMenuItem addChild;
    public      static JTextArea info;

    public GUI()
    {
        try
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } 
        catch (Exception e)
        {
            System.err.println("Failed to load windows look and feel");
            e.printStackTrace();
        }

        this.setLayout(new BorderLayout());
        this.add(menu(), BorderLayout.NORTH);
        this.add(new TableSelectionDemo(), BorderLayout.CENTER);
        this.add(ChildInfoDisplay(), BorderLayout.EAST);

        this.setTitle("Kinder aus kraus");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        //Display the window.
        this.pack();
        this.setVisible(true);
        this.setSize(500, 500);
        

    }


    public static void main(String[] args)
    {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
            	
               Version.connection(null);
               TableSelectionDemo tsd = new TableSelectionDemo();
              
               
                //d.setContent();
                tsd.printFriendNick();
                new GUI();
            }
        });
    }

    
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == exit)
            System.exit(0);

        //Open up a form if a new child should be added
        if(e.getSource() == addChild)
            new form();
    }















    //***************GUI METHODS***************

    private JMenuBar menu()
    {
         //Create the menu bar.
        menuBar = new JMenuBar();

        //Build the first menu.
        JMenu archive = new JMenu("Arkiv");
        JMenu help = new JMenu("Hjälp");

        exit = new JMenuItem("Avsluta");
        writeOut = new JMenuItem("Skriv ut...");
        save = new JMenuItem("Spara");
        addChild = new JMenuItem("Nytt barn");

        exit.addActionListener(this);
        addChild.addActionListener(this);

        archive.add(addChild);
        archive.add(save);
        archive.add(writeOut);
        archive.add(exit);

        menuBar.add(archive);
        menuBar.add(help);

        return menuBar;
    }

    public JScrollPane ChildInfoDisplay()
    {
        info = new JTextArea("Testaaaaaaqaaaa\n");
        info.setBackground(Color.red);
        info.setEditable(true);
        JScrollPane scroll = new JScrollPane(info);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        
        return scroll;
    }
}
